
@extends('admin.home.main')
@section('body')
<section id="main-content">
    <section class="wrapper">
        <h3>订单详情</h3>
        <hr>
        <div style="width:100%; height:50px; line-height:50px; margin-bottom:15px;border:1px solid #eee;
        background:rgba(243,243,243,1)">
            <span style="color:red;font-size:16px; font-weight:bold; float:left;">
                @if($orderInfo['product_type'] == 1 && $orderInfo['payment_time'] != '')
                    当前订单状态：交易成功
                @else
                    当前订单状态：{{$orderInfo['status_name']}}
                @endif
            </span>
            @if($orderInfo['composition_status'] != 30)
            <a href="/admin/order/cancelorder/{{$orderInfo['id']}}" style="float:right; margin-right:10px;">取消订单</a>
            @endif
        </div>
        <div class="row mt">
            <div class="col-md-12">
                <div class="content-panel">
                    <p style="font-weight: bold; font-size: 14px; float:left; margin-left:10px;"> 基本信息</p>
                    @if($orderInfo['product_type'] == 2 && $orderInfo['pay_status'] == 40 &&
                    $orderInfo['composition_status'] == 30)
                        <a href="javascript:;" style="float:right; margin-right:10px" onclick="modifySendGoodsMsg()
">更新发货信息</a>
                    @endif
                    <table class="table table-striped table-advance table-hover">
                        <input type="hidden" id="order_id" value="{{$orderInfo['id']}}">
                        <input type="hidden" name="_token" id="_token" value="{{csrf_token()}}">
                        <input type="hidden" name="member_id" id="member_id" value="{{$orderInfo['member_id']}}">
                        <tr>
                            <th>订单编号</th>
                            <th>发货单流水号</th>
                            <th>用户账号</th>
                            <th>支付方式</th>
                            <th>订单类型</th>
                        </tr>
                        <tr>
                            <td>{{$orderInfo['ordernum']}}</td>
                            <td id="stream_id">
                                @if($orderInfo['product_type'] == 2)
                                    @if($orderInfo['kd_stream_id'] != '')
                                        {{$orderInfo['kd_stream_id']}}
                                    @else
                                        未发货
                                    @endif
                                @else
                                    -
                                @endif
                            </td>
                            <td>{{$orderInfo['member_nick']}}</td>
                            <td>
                                @if($orderInfo['payment_type'] == 1)
                                    微信支付
                                @endif
                            </td>
                            <td>普通订单</td>
                        </tr>
                        <tr>
                            <th>配送方式</th>
                            <th>物流单号</th>
                            <th>快递公司</th>
                            <th></th>
                            <th></th>
                        </tr>
                        <tr>
                            <td id="delivery_func">
                                @if($orderInfo['product_type'] == 2)
                                    @if($orderInfo['delivery_func'] == 1)
                                        送货上门
                                    @elseif($orderInfo['delivery_func'] == 2)
                                        自己提取
                                    @else
                                        未发货
                                    @endif
                                @else
                                    -
                                @endif
                            </td>
                            <td id="ticket_id">
                                @if($orderInfo['product_type'] == 2)
                                    @if($orderInfo['kd_ticket_id'] > 0)
                                        {{$orderInfo['kd_ticket_id']}}
                                    @else
                                        未发货
                                    @endif
                                @else
                                    -
                                @endif
                            </td>
                            <td id="customer">
                                @if($orderInfo['product_type'] == 2)
                                    @if($orderInfo['customer'] != '')
                                        @foreach($customer_list as $ctm=>$cst)
                                            @if($orderInfo['customer'] == $ctm)
                                                {{$cst}}
                                            @endif
                                        @endforeach
                                    @else
                                        未发货
                                    @endif
                                @else
                                    -
                                @endif
                            </td>
                            <td id="save"></td>
                            <td></td>
                        </tr>
                    </table>

                    <p style="font-weight: bold; font-size: 14px; float:left; margin-left:10px;"> 收货人信息</p>
                    <table class="table table-striped table-advance table-hover">
                        <tr>
                            <th>收货人</th>
                            <th>手机号码</th>
                            <th>邮政编号</th>
                            <th>收货地址</th>
                        </tr>
                        <tr>
                            <td>{{$orderInfo['member_nick']}}</td>
                            <td>{{$orderInfo['telephone']}}</td>
                            @if(!empty($addressInfo))
                                <td>{{$addressInfo->zip_code}}</td>
                                <td>
                                    {{$addressInfo->province_name}} {{$addressInfo->city_name}}
                                {{$addressInfo->county_name}} {{$addressInfo->address}}
                                </td>

                            @else
                                <td>-</td>
                                <td>-</td>
                            @endif

                        </tr>

                    </table>

                    <p style="font-weight: bold; font-size: 14px; float:left; margin-left:10px;"> 产品信息</p>
                    <table class="table table-striped table-advance table-hover">
                        <tr>
                            <th>商品图片</th>
                            <th>商品名称</th>
                            <th>价格/货号</th>
                            <th>数量</th>
                            <th>库存</th>
                            <th>小计</th>
                        </tr>
                        @foreach($orderInfo['product_list'] as $optm=>$opst)
                        <tr>
                            <td><img src="{{$opst['productinfo']['picture']}}" width="50" height="50" alt=""></td>
                            <td>{{$opst['productinfo']['name']}}</td>
                            <td>￥{{$opst['productinfo']['price']}}@if(isset($opst['productinfo']['item_num']))
                                    <br>{{$opst['productinfo']['item_num']}}@endif</td>
                            <td>{{$opst['num']}}件/套</td>
                            <td>{{$opst['productinfo']['stock']}}件/套</td>
                            <td>￥{{intval($opst['productinfo']['price'])*intval($opst['num'])}}</td>
                        </tr>
                        @endforeach
                    </table>

                    <p style="font-weight: bold; font-size: 14px; float:left; margin-left:10px;"> 费用信息</p>
                    <table class="table table-striped table-advance table-hover">
                        <tr>
                            <th>商品合计</th>
                            <th>运费</th>
                            <th>订单总金额</th>
                            <th>应付金额</th>
                        </tr>
                        <tr>
                            <td>￥{{array_sum($orderInfo['amount'])}}</td>
                            <td>￥{{$orderInfo['postage']}}</td>
                            <td>￥{{array_sum($orderInfo['amount'])}}</td>
                            <td>￥{{array_sum($orderInfo['amount'])}}</td>
                        </tr>

                    </table>
                </div>
            </div>
        </div>
    </section>
</section>
<script type="text/javascript">
    $(document).on('click','#io_save',function(){
        var _token = $('#_token').val(),
            _orderId = $('#order_id').val(),
            _memberId = $('#member_id').val(),
            _streamId = $('#io_stream_id').val(),
            _ticketId = $('#io_ticket_id').val(),
            _delivery = $('#io_delivery_func').val(),
            _customer = $('#io_customer').val();

        if(!_streamId){
            alert('请输入快递流水号');
            return false;
        }

        if(!_ticketId) {
            alert('请输入快递单号');
            return false;
        }

        if(_delivery == 0){
            alert('请选择配送方式');
            return false;
        }

        if(_customer == 0){
            alert('请选择快递公司');
            return false;
        }

        $.ajax({
            url:'/admin/order/modifylogisticsmsg',
            type:'post',
            data:{'_token':_token,'id':_orderId,'member_id':_memberId,'stream_id':_streamId,'ticket_id':_ticketId,
                'delivery':_delivery,
                'customer':_customer},
            dataType:'json',
            success:function(data){
                if(data.code == 200){
                    alert('物流信息更新成功');
                }else{
                    alert('物流信息更新失败');
                }
                location.reload();
            }
        })
    })


    function modifySendGoodsMsg(){
        var stream_id = $('#stream_id'),
            delivery_func = $('#delivery_func'),
            ticket_id = $('#ticket_id'),
            customer = $('#customer'),
            save = $('#save');

        var delivery_func_html = '<select class="form-control" style="width:100px;" id="io_delivery_func" ' +
            'name="delivery_func"><option value="0">请选择</option><option value="1">送货上门</option><option ' +
            'value="2">自己提取</option></select>';


        var customer_html = '<select class="form-control" style="width:100px;" id="io_customer" ' +
            'name="customer"><option ' +
            'value="0">请选择</option><option value="youzhengguonei">邮政包裹</option><option value="ems">EMS' +
            '</option><option value="shunfeng">顺丰快递</option><option value="shentong">申通快递</option>' +
            '<option value="yuantong">圆通快递</option><option value="zhongtong">中通快递</option><option ' +
            'value="huitongkuaidi">百世汇通</option><option value="yunda">韵达快递</option><option value=' +
            '"zhaijisong">宅急送</option><option value="tiantian">天天快递</option><option value="jd">京东</option>' +
            '</select>';


        stream_id.html('<input type="text" style="width:150px;" name="stream_id" id="io_stream_id" placeholder="请输入快递流水号" ' +
            'class="form-control">');
        delivery_func.html(delivery_func_html);
        ticket_id.html('<input type="text" style="width:150px;" name="ticket_id" id="io_ticket_id" ' +
            'placeholder="请输入快递单号" class="form-control">');
        customer.html(customer_html);
        save.html('<button type="button" class="btn btn-primary" id="io_save">保存信息</button>');
    }
</script>
@endsection